<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
</head>

<body>
    请输入账号<input type="number" name="" id="user_js">
    请输入密码<input type="password" name="" id="password_js">
    <input type="checkbox" id="input_js">记住账号密码
    <button id="button_js">登录</button>
</body>

</html>
<script>
  
    if(document.cookie){
        //将cookie内容格式化
        var newCook = JSON.parse(document.cookie.split("; ")[0].split("=")[1]);
        alert('免登录跳转中，点击确定才能跳转哦')

        var timerId = setTimeout(function(){

            user_js.value = newCook.user;
            password_js.value = newCook.pass;
            //cookie内存放有内容时免登录跳转页面
            window.location.replace('http://www.baidu.com');
            
        clearTimeout(timerId);
        },2000);

    }

    button_js.onclick = function () {

        var user_number = user_js.value;
        var password_number = password_js.value;

        if (user_number && password_number) {
            // console.log('登陆成功');
            alert('登录成功，进行跳转')
            if(input_js.checked){
                //向cookie内存放
                var date = new Date();
                date.setTime(date.getTime() + 60 * 1000);
                
                var str =  {'user':`${user_number}`,'pass':`${password_number}`}
                var newStr = JSON.stringify(str);
                
                // document.cookie("str",newStr,{export:1})
                    var date = new Date();
                 date.setTime(date.getTime() + 60 * 2000);

                document.cookie = `str = ${newStr};expires = ${date.toUTCString()}`

            }
            window.location.replace('http://www.baidu.com');
            

        } else {
            alert('请输入密码')
        }
    }
</script>